package com.resourcestore.utils.tag;

import java.util.Map;

public class Pagination {

	// 当前页
	private int pageNo;
	// 记录总数
	private int total;
	// 每页最大显示记录条数
	private int pageLength = 20;

	//private int totalPage;

	public Map addStartNumRowNumToMap(Map map) {
		map.put("startNum", getCurrentRecord());
		map.put("rowNum", pageLength);
		return map;
	}

	/**
	 * @return Returns the currentPage.
	 */
	public int getPageNo() {
		if (pageNo == 0)
			return 1;
		else
			return pageNo;
	}

	/**
	 * @param currentPage
	 *            The currentPage to set.
	 */
	public void setPageNo(int currentPage) {
		this.pageNo = currentPage;
	}

	/**
	 * @return Returns the totalRecord.
	 */
	public int getTotal() {
		return total;
	}

	/**
	 * @param totalRecord
	 *            The totalRecord to set.
	 */
	public void setTotal(int totalRecord) {
		this.total = totalRecord;
	}

	/**
	 * @return Returns the pageLength.
	 */
	public int getPageLength() {
		return pageLength;
	}

	/**
	 * @param pageLength
	 *            The pageLength to set.
	 */
	public void setPageLength(int pageLength) {
		this.pageLength = pageLength;
	}

	/**
	 * 获取页面总数
	 * 
	 * @return
	 */
	public int getTotalPage() {
		return (total % pageLength == 0) ? total / pageLength : total
				/ pageLength + 1;
	}

	/**
	 * 首页
	 * 
	 * @return
	 */
	public int getFirstPage() {
		return 1;
	}

	/**
	 * 末页
	 * 
	 * @return
	 */
	public int getLastPage() {
		return getTotalPage();
	}

	/**
	 * 获取当前页面初始记录数
	 * 
	 * @return
	 */
	public int getCurrentRecord() {
		if (pageNo == 0)
			return 0;

		return pageLength * (pageNo - 1);
	}
}
